package com.sugon.controller.basics;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.PlanDraCheckEntity;
import com.sugon.service.PlanDraCheckService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 非标零件制作审批Controller
 *
 * @author sugon
 * @date 2019-08-13 10:50:10
 */
@Controller
@RequestMapping("plandracheck")
public class PlanDraCheckController {
    @Autowired
    private PlanDraCheckService planDraCheckService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("plandracheck:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<PlanDraCheckEntity> planDraCheckList = planDraCheckService.queryList(query);
        int total = planDraCheckService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(planDraCheckList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("plandracheck:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        PlanDraCheckEntity planDraCheck = planDraCheckService.queryObject(id);

        return R.ok().put("planDraCheck", planDraCheck);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("plandracheck:save")
    @ResponseBody
    public R save(@RequestBody PlanDraCheckEntity planDraCheck) {
        planDraCheckService.save(planDraCheck);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("plandracheck:update")
    @ResponseBody
    public R update(@RequestBody PlanDraCheckEntity planDraCheck) {
        planDraCheckService.update(planDraCheck);

        return R.ok();
    }

    /**
     * 车间室主任审批
     */
    @RequestMapping("/deptCheck")
    @RequiresPermissions("plandracheck:deptCheck")
    @ResponseBody
    public R deptCheck(@RequestBody PlanDraCheckEntity planDraCheck) {
        planDraCheckService.deptCheck(planDraCheck);

        return R.ok();
    }

    /**
     * PE审批
     */
    @RequestMapping("/peCheck")
    @RequiresPermissions("plandracheck:peCheck")
    @ResponseBody
    public R peCheck(@RequestBody PlanDraCheckEntity planDraCheck) {
        planDraCheckService.peCheck(planDraCheck);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("plandracheck:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        planDraCheckService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<PlanDraCheckEntity> list = planDraCheckService.queryList(params);

        return R.ok().put("list", list);
    }
}
